home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / nehe7.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  6.3 KB  |  134 lines

  1.     dim light                       ' Lighting ON / OFF
  2.     dim xrot#                       ' X Rotation
  3.     dim yrot#                       ' Y Rotation
  4.     dim xspeed#                     ' X Rotation Speed
  5.     dim yspeed#                     ' Y Rotation Speed
  6.     dim z#                          ' Depth Into The Screen    
  7.     z# = -5
  8.     dim LightAmbient# (3)           ' Ambient Light Values
  9.     LightAmbient# = Vec4 (.5, .5, .5, 1)
  10.     dim LightDiffuse# (3)           ' Diffuse Light Values 
  11.     LightDiffuse# = Vec4 (1, 1, 1, 1)
  12.     dim LightPosition# (3)          ' Light Position
  13.     LightPosition# = Vec4 (0, 0, 2, 1)
  14.     dim filter                      ' Which Filter To Use
  15.     dim texture(2)                  ' Storage for 3 textures
  16.     dim image
  17.     dim a$
  18.  
  19.     ' Load textures
  20.  
  21.     glGenTextures (3, texture)                      ' Generate 3 textures
  22.     dim i
  23.  
  24.     image = LoadImage ("Data/Crate.bmp")            ' Load crate image
  25.  
  26.     glBindTexture (GL_TEXTURE_2D, texture (0))
  27.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
  28.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  29.     glTexImage2D (GL_TEXTURE_2D, 0, 3, ImageWidth(image), ImageHeight(image), 0, ImageFormat(image), ImageDataType(image), image)
  30.     
  31.     glBindTexture (GL_TEXTURE_2D, texture (1))
  32.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  33.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
  34.     glTexImage2D (GL_TEXTURE_2D, 0, 3, ImageWidth(image), ImageHeight(image), 0, ImageFormat(image), ImageDataType(image), image)
  35.     
  36.     glBindTexture (GL_TEXTURE_2D, texture (2))
  37.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  38.     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST)
  39.     gluBuild2DMipmaps (GL_TEXTURE_2D, 3, ImageWidth(image), ImageHeight(image), ImageFormat(image), ImageDataType(image), image)
  40.  
  41.     DeleteImage (image)
  42.     
  43.     ' Init OpenGL
  44.     
  45.     glEnable(GL_TEXTURE_2D)                             ' Enable Texture Mapping
  46.     glShadeModel(GL_SMOOTH)                             ' Enable Smooth Shading
  47.     glClearColor(0.0, 0.0, 0.0, 0.5)                    ' Black Background
  48.     glClearDepth(1.0)                                   ' Depth Buffer Setup
  49.     glEnable(GL_DEPTH_TEST)                             ' Enables Depth Testing
  50.     glDepthFunc(GL_LEQUAL)                              ' The Type Of Depth Testing To Do
  51.     glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)   ' Really Nice Perspective Calculations
  52.  
  53.     glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient#)     ' Setup The Ambient Light
  54.     glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse#)     ' Setup The Diffuse Light
  55.     glLightfv(GL_LIGHT1, GL_POSITION,LightPosition#)    ' Position The Light
  56.     glEnable(GL_LIGHT1)                                 ' Enable Light One
  57.  
  58.     ' Main loop
  59.     while true
  60.         
  61.         ' Draw scene        
  62.         glClear (GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)    ' Clear The Screen And The Depth Buffer
  63.         glLoadIdentity ()                                       ' Reset The View       
  64.         glTranslatef (0.0,0.0,z#)
  65.     
  66.         glRotatef(xrot#,1.0,0.0,0.0)
  67.         glRotatef(yrot#,0.0,1.0,0.0)
  68.     
  69.         glBindTexture(GL_TEXTURE_2D, texture (filter))
  70.     
  71.         glBegin(GL_QUADS)
  72.             ' Front Face
  73.             glNormal3f( 0.0, 0.0, 1.0)
  74.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  75.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  76.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)
  77.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)
  78.             ' Back Face
  79.             glNormal3f( 0.0, 0.0,-1.0)
  80.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)
  81.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  82.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  83.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)
  84.             ' Top Face
  85.             glNormal3f( 0.0, 1.0, 0.0)
  86.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  87.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0,  1.0,  1.0)
  88.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0,  1.0,  1.0)
  89.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  90.             ' Bottom Face
  91.             glNormal3f( 0.0,-1.0, 0.0)
  92.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, -1.0, -1.0)
  93.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, -1.0, -1.0)
  94.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  95.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  96.             ' Right face
  97.             glNormal3f( 1.0, 0.0, 0.0)
  98.             glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, -1.0)
  99.             glTexCoord2f(1.0, 1.0): glVertex3f( 1.0,  1.0, -1.0)
  100.             glTexCoord2f(0.0, 1.0): glVertex3f( 1.0,  1.0,  1.0)
  101.             glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0,  1.0)
  102.             ' Left Face
  103.             glNormal3f(-1.0, 0.0, 0.0)
  104.             glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, -1.0)
  105.             glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0,  1.0)
  106.             glTexCoord2f(1.0, 1.0): glVertex3f(-1.0,  1.0,  1.0)
  107.             glTexCoord2f(0.0, 1.0): glVertex3f(-1.0,  1.0, -1.0)
  108.         glEnd()    
  109.         xrot# = xrot# + xspeed#
  110.         yrot# = yrot# + yspeed#
  111.         SwapBuffers ()
  112.         
  113.         a$ = inkey$()
  114.         if a$ = "L" or a$ = "l" then
  115.             light = not light
  116.             if not light then
  117.                 glDisable (GL_LIGHTING)
  118.             else
  119.                 glEnable (GL_LIGHTING)
  120.             endif
  121.         endif
  122.         if a$ = "F" or a$ = "f" then
  123.             filter = filter + 1
  124.             if filter > 2 then
  125.                 filter = 0
  126.             endif
  127.         endif
  128.         if ScanKeyDown (VK_PRIOR)   then    z# = z# - 0.2               endif
  129.         if ScanKeyDown (VK_NEXT)    then    z# = z# + 0.2               endif
  130.         if ScanKeyDown (VK_UP)      then    xspeed# = xspeed# - 0.01    endif
  131.         if ScanKeyDown (VK_DOWN)    then    xspeed# = xspeed# + 0.01    endif
  132.         if ScanKeyDown (VK_RIGHT)   then    yspeed# = yspeed# + 0.01    endif
  133.         if ScanKeyDown (VK_LEFT)    then    yspeed# = yspeed# - 0.01    endif        
  134.     wend